package com.zx.account.model;

import com.zx.util.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @version v1.0
 * @Project: managing-self
 * @Title: ResponseDto
 * @Description: 请求统一响应值
 * @author: zhangxue
 * @date: 2019年10月5日下午2:32:25
 * @company: 未知
 * @Copyright: Copyright (c) 2015
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ResponseDto<T> {

    private int code;

    private String msg;

    private T data;

    public static <T> ResponseDto<T> ok(T data) {
        return new ResponseDto<>(Constants.RESPONSE_OK_CODE, Constants.RESPONSE_OK_MSG, data);
    }

    public static <T> ResponseDto<T> ok(String msg, T data) {
        return new ResponseDto<>(Constants.RESPONSE_OK_CODE, msg, data);
    }

    public static <T> ResponseDto<T> no(String msg) {
        return new ResponseDto<>(Constants.RESPONSE_NO_CODE, msg, null);
    }

    public static <T> ResponseDto<T> no(T data) {
        return new ResponseDto<>(Constants.RESPONSE_NO_CODE, Constants.RESPONSE_NO_MSG, data);
    }

    public static <T> ResponseDto<T> no(String msg, T data) {
        return new ResponseDto<>(Constants.RESPONSE_NO_CODE, msg, data);
    }
}
